package com.itheima.morning.demo01;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Demo03 {
    public static void main(String[] args) {
        ThreadPoolExecutor pool = null;
        try {
            pool = new ThreadPoolExecutor(2,10,2
                    , TimeUnit.SECONDS, new ArrayBlockingQueue<>(10), Executors.defaultThreadFactory()
                    , new ThreadPoolExecutor.AbortPolicy());
            for (int i = 0; i < 21; i++) {
                pool.submit(()->{
                    System.out.println(Thread.currentThread().getName() + "在执行了！");
                });
            }
        } catch (Exception e) {
            System.out.println("排队的人太多了，应付不过来了！");;
        } finally {
            pool.shutdown();
        }
    }
}
